Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/1982 #2051

Merged
merged 17 commits into from
Nov 21, 2023
Merged

Fix/1982 #2051

merged 17 commits into from
Nov 21, 2023

Conversation

EmiM
Copy link
Contributor

@EmiM EmiM commented Nov 9, 2023

Pull Request Checklist

  • I have linked this PR to related GitHub issue.
  • I have updated the CHANGELOG.md file with relevant changes (the file is located at the root of monorepo).

(Optional) Mobile checklist

Please ensure you completed the following checks if you did any changes to the mobile package:

  • I have run e2e tests for mobile
  • I have updated base screenshots for visual regression tests

) {
super()
}

private dialPeer = async (peerAddress: string) => {
if (this.dialedPeers.has(peerAddress)) {
console.log(`Peer ${peerAddress} already dialed, not dialing`) // TODO: remove log
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work with min/max connections? Once a peer has been dialed, are they never dialed again? Would that mean we might run out of peers to dial if enough peers disconnect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every dialed peer is added to libp2p's internal address book. Autodialer checks connections every X minutes. Technically (according to code) if number of connections falls below set minConnections (e.g everyone disconnect from us) autodialer should look up peers in libp2p peerStore and try to open connections again.

dialTimeout: 120_000,
maxParallelDials: 10,
autoDial: true, // It's a default but let's set it to have explicit information
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea!

@@ -9,6 +9,9 @@ This is the very simple algorithm for evaluating the most wanted peers.
4. We end up with mix of last seen and most uptime descending array of peers, the it is enchanced to libp2p address.
*/
export const sortPeers = (peersAddresses: string[], stats: NetworkStats[]): string[] => {
peersAddresses = peersAddresses.filter(add =>
add.match(/^\/dns4\/[a-z0-9]{56}.onion\/tcp\/80\/ws\/p2p\/[a-zA-Z0-9]{46}$/g)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this filter helpful?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2027 (comment) the second part of my comment is connected with that. Because of this we have invalid addresses (only peerIds) saved in localdb. This is added to filter them out.

@EmiM EmiM marked this pull request as ready for review November 20, 2023 10:52
@EmiM EmiM requested a review from vinkabuki November 20, 2023 11:13
@@ -9,6 +9,9 @@ This is the very simple algorithm for evaluating the most wanted peers.
4. We end up with mix of last seen and most uptime descending array of peers, the it is enchanced to libp2p address.
*/
export const sortPeers = (peersAddresses: string[], stats: NetworkStats[]): string[] => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets' change a name to filterAndSortPeers or something

packages/backend/src/nest/storage/storage.service.ts Outdated Show resolved Hide resolved
}

public async processOneItem() {
if (!this.isActive) return
// if (!this.isActive) return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover?

@EmiM EmiM merged commit b51de0d into develop Nov 21, 2023
21 of 24 checks passed
@siepra siepra deleted the fix/1982 branch December 8, 2023 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants